home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / comm2 / mmstrtrk.lha / MM / Rexx / CheckWildcard.rexx next >
OS/2 REXX Batch file  |  1995-06-24  |  2KB  |  115 lines

  1. /* RH 24.06.95 */
  2.  
  3. parse arg addr from to .
  4.  
  5. addr    = strip(addr)
  6. from    = replace(strip(from), '*', '#?')
  7. to        = replace(strip(to),   '*', '#?')
  8.  
  9. if addr='' | from='' | to='' then
  10.     do
  11.     say 'Usage: [RX] CheckWildcard[.rexx] <address> <from-pattern> <to-pattern>'
  12.         say
  13.         exit
  14.   end
  15.  
  16.  
  17. address 'MAILMANAGER'
  18.  
  19.  
  20. if Check_Pattern(from, addr)=0 then
  21.     do
  22.         say
  23.         say 'The from-pattern "'from'" does not match with address "'addr'".'
  24.         say
  25.         exit
  26.     end
  27.  
  28.  
  29. say
  30.  
  31. new = Resolve_Wildcard(addr, from, to)
  32.  
  33. say
  34. say addr 'will be remapped to' new
  35. say
  36.  
  37. exit
  38.  
  39.  
  40. Check_Pattern: procedure Expose result
  41.  
  42.   arg pattern, string.0
  43.  
  44.     string.count    = 1
  45.     result.                = 0
  46.  
  47.     MM_SearchInStem 'string' 'result' pattern 'STR'
  48.  
  49.     result                = result.0
  50.  
  51. return result.count>0
  52.  
  53.  
  54. Log: procedure
  55.  
  56.     parse arg text
  57.  
  58.     say text
  59. return
  60.  
  61.  
  62. Replace: procedure
  63.  
  64.     parse arg string,new,old
  65.  
  66.     do while index(string, old)~=0
  67.         interpret "parse var string l '"old"' r"
  68.         string = l || new || r
  69.     end
  70.  
  71. return string
  72.  
  73.  
  74. Resolve_Wildcard: procedure
  75.  
  76.   parse arg address, from, to
  77.  
  78.     parse var address a.1 ':' a.2 '/' a.3 '.' a.4 '@' a.5
  79.     parse var from        f.1 ':' f.2 '/' f.3 '.' f.4 '@' f.5
  80.     parse var to            t.1 ':' t.2 '/' t.3 '.' t.4 '@' t.5
  81.  
  82.     do n=1 to 5
  83.         wposf    = pos('*', f.n)
  84.         wpost    = pos('*', t.n)
  85.  
  86.         select
  87.             when wposf=0 & wpost=0    then r.n = t.n
  88.             when wposf>0 & wpost=0    then r.n = f.n
  89.             when wposf>0 & wpost>0    then
  90.                 do
  91.                     dpos    = compare(f.n, t.n)
  92.  
  93.                     if dpos=0    then tmp = ''
  94.                     else                     tmp = substr(t.n, dpos, wpost-dpos)
  95.  
  96.                     r.n        = left(f.n, max(dpos-1, 0)) || tmp || substr(a.n, wposf)
  97.                 end
  98.             otherwise
  99.                 do
  100.                     call Log('*** WILDCARD-ERROR: Unable to resolve' f.n '->' t.n '('from '->' to')')
  101.           call Log('                    Remap NOT possible!')
  102.  
  103.                     do m=1 to 5
  104.                         r.m = a.m
  105.                     end
  106.  
  107.                     leave n
  108.                 end
  109.         end
  110.     end
  111.  
  112. return r.1':'r.2'/'r.3'.'r.4'@'r.5
  113.  
  114.  
  115.